package crudfx.util;
import javafx.animation.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class Waiter{
    public var action:function():Void;
    public var onDone:function():Void;
    public var delay:Duration=0.1s;
    var isDone:Boolean;
    public var isFinished:Boolean;
    public function serve():Void{
        isFinished=false;
        isDone=false;
        var timeline:Timeline=Timeline{
            repeatCount:Timeline.INDEFINITE
            keyFrames:KeyFrame{
                time:delay
                action:function():Void{
                    if(not isFinished){
                        if(isDone){
                            isFinished=true;
                            timeline.stop();
                            onDone();
                            }
                        }
                    }
                }
            };
        timeline.play();
        ThreadTask{
            override public function threadAction():Void{
                action();
                isDone=true;                
                }
            }.go();
        }
    }
